import axios from 'axios'
const fetchCates = (params = {}) => {
  return axios.get('https://api.it120.cc/conner/cms/category/list', {params})
}

export default {
  namespace: 'count',
  // 管理状态的
  state: {
    num: 0,
    cates: []
  },
  // 处理数据  编译成 reducer中 一个 action
  reducers: {
    // 对于action重命名 命名空间名/add
    add(state: any, action: any) {
      state.num += action.data;
      return {
        ...state
      }
    },
    initCates (state: any, action:any) {
      state.cates = action.data
      
      return {
        ...state
      }
    }
  },
  // 相当于 vuex中的action 处理异步
  effects: {
    // 编译成 action  type  模块/名字  count/getCates
    *getCates(action: any, { put, call }: any) {
        const res = yield call(fetchCates, action.params)
        if (res.data.code === 0) {
          yield  put({
            type: 'initCates',
            data: res.data.data
          })
        }
        
    },
  },
};
        